23 #define foreach(x, v) for (typeof (v).begin() x=(v).begin(); x !=(v).end(); ++x)
24 #define For(i, a, b) for (int i=(a); i<(b); ++i)
25 #define D(x) cout << #x " is " << x << endl
29 bool visited
[MAXN
][MAXN
][MAXN
];
31 bool black
[MAXN
][MAXN
][MAXN
];
33 int dx
[] = { -1, +0, +1, +1, +0, -1 };
34 int dy
[] = { +0, -1, -1, +0, +1, +1 };
35 int dz
[] = { +1, +1, +0, -1, -1, +0 };
37 bool inside(int x
, int y
, int z
) {
38 return x
>= 0 and y
>= 0 and z
>= 0;
41 bool blackCanWin(int sx
, int sy
, int sz
, int n
) {
42 memset(visited
, 0, sizeof visited
);
43 assert(inside(sx
, sy
, sz
) and black
[sx
][sy
][sz
]);
45 visited
[sx
][sy
][sz
] = true;
46 q
.push(sx
); q
.push(sy
); q
.push(sz
);
47 while (q
.size() > 0) {
48 int x
= q
.front(); q
.pop();
49 int y
= q
.front(); q
.pop();
50 int z
= q
.front(); q
.pop();
51 //printf("popped %d, %d, %d\n", x, y, z);
52 for (int k
= 0; k
< 6; ++k
) {
56 if (!inside(nx
, ny
, nz
)) continue;
57 if (!black
[nx
][ny
][nz
]) continue;
58 if (visited
[nx
][ny
][nz
]) continue;
59 q
.push(nx
); q
.push(ny
); q
.push(nz
);
60 visited
[nx
][ny
][nz
] = true;
63 bool seenX
= false, seenY
= false, seenZ
= false;
64 for (int x
= 0; x
<= n
; ++x
) {
65 for (int y
= 0; y
<= n
; ++y
) {
66 for (int z
= 0; z
<= n
; ++z
) {
67 if (!black
[x
][y
][z
]) continue;
68 if (!visited
[x
][y
][z
]) continue;
72 //printf("saw black cell (%d, %d, %d)\n", x, y, z);
76 //printf("seenX = %d, seenY = %d, seenZ = %d\n", seenX, seenY, seenZ);
77 return seenX
and seenY
and seenZ
;
82 while (cin
>> n
>> m
) {
83 if (n
== 0 and m
== 0) break;
84 memset(visited
, 0, sizeof visited
);
85 memset(black
, 0, sizeof black
);
87 for (int k
= 0; k
< m
; ++k
) {
90 black
[x
][y
][z
] = true;
93 bool blackWins
= false;
94 for (int x
= 0; x
<= n
; ++x
) {
95 for (int y
= 0; y
<= n
; ++y
) {
96 for (int z
= 0; z
<= n
; ++z
) {
97 if (!black
[x
][y
][z
]) continue;
98 if (visited
[x
][y
][z
]) continue;
99 if (x
!= 0 and y
!= 0 and z
!= 0) continue;
101 assert(black
[x
][y
][z
]);
102 blackWins
|= blackCanWin(x
, y
, z
, n
);
104 x
= y
= z
= n
; // ultra break
109 printf("%s\n", blackWins
? "Benny" : "Willy");